<?php
/**
 * 设计师发布服务流程
 */
use Doraemon\tools\Log;
use Doraemon\service\DesignerService\WholeHouse as sWholeHouse;
use Doraemon\model\DesignerService\ServiceContentRecord as mServiceContentRecord;

class PublishServiceProcessAction extends ActionPlugin {

    public function main()
    {
        Log::info('设计师发布服务流程开始接收到事件信息', $this->messageBody);
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        if (strstr($table, mServiceContentRecord::_TABLE_NAME)) {
            $uid = $this->messageBody['data']['uid'] ?? 0;
            $eventType = $this->messageBody['type'] ?? '';
            $dataType = $this->messageBody['data']['data_type']; // 数据类别 1=草稿；2=发布
            $auditStatus = $this->messageBody['data']['audit_status']; // 审核状态 1=待审核 2=通过 3=不通过
            if ($eventType == 'insert'
                && $dataType == mServiceContentRecord::TYPE_PUBLISHED
                && $auditStatus == mServiceContentRecord::AUDIT_PASS
            ) {
                // 处理全屋设计H5用户展示状态字段
                sWholeHouse::syncShowStatus($uid);
            }
        }
        Log::info('设计师违规监测变化结束接收到的事件', compact('uid', 'message'));
        $this->setSuccess();
    }
}